package service

import (
	"kingbloc.dts/models"
	"kingbloc.dts/tools"
	"kingbloc.util/util"
)

func FindAccountByMob(mob string) *model.Account {

	if !util.RegexpMobile.MatchString(mob) {
		return nil
	}

	user := tool.UserInfoByMob(mob)
	if user == nil {
		return nil
	}

	return FindAccountBySSOId(user.Id)

}

func FindAccountById(id int64) *model.Account {
	return new(model.Account).ById(id)

}
func FindAccountBySSOId(id int64) *model.Account {
	return model.FindAccountBySsoId(id)

}

// 我的申请
func MyApproves(accountId int64) []*model.Approve {
	return new(model.Approve).ByProposerAccountIdId(accountId)
}

// 我的审批
func Approves(accountId int64) []*model.Approve {
	return new(model.Approve).ByExaminerAccountIdId(accountId)
}

func Approve(apid, aid int64) *model.Approve {

	return new(model.Approve).ByIdAndAid(apid, aid)

}
